package com.ruoyi.project.surveys.controller;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.surveys.domain.SurveysQuestionMotif;
import com.ruoyi.project.surveys.service.ISurveysQuestionMotifService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 题目主题Controller
 * 
 * @author zhimin-hu
 * @date 2020-05-02
 */
@RestController
@RequestMapping("/surveys/motif")
public class SurveysQuestionMotifController extends BaseController
{
    @Autowired
    private ISurveysQuestionMotifService surveysQuestionMotifService;

    /**
     * 查询题目主题列表
     */
    @PreAuthorize("@ss.hasPermi('surveys:motif:list')")
    @GetMapping("/list")
    public AjaxResult list(SurveysQuestionMotif surveysQuestionMotif)
    {
        List<SurveysQuestionMotif> list = surveysQuestionMotifService.selectSurveysQuestionMotifList(surveysQuestionMotif);
        return AjaxResult.success(list);
    }

    /**
     * 导出题目主题列表
     */
    @PreAuthorize("@ss.hasPermi('surveys:motif:export')")
    @Log(title = "题目主题", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SurveysQuestionMotif surveysQuestionMotif)
    {
        List<SurveysQuestionMotif> list = surveysQuestionMotifService.selectSurveysQuestionMotifList(surveysQuestionMotif);
        ExcelUtil<SurveysQuestionMotif> util = new ExcelUtil<SurveysQuestionMotif>(SurveysQuestionMotif.class);
        return util.exportExcel(list, "motif");
    }

    /**
     * 获取题目主题详细信息
     */
    @PreAuthorize("@ss.hasPermi('surveys:motif:query')")
    @GetMapping(value = "/{questionMotifId}")
    public AjaxResult getInfo(@PathVariable("questionMotifId") Long questionMotifId)
    {
        return AjaxResult.success(surveysQuestionMotifService.selectSurveysQuestionMotifById(questionMotifId));
    }

    /**
     * 新增题目主题
     */
    @PreAuthorize("@ss.hasPermi('surveys:motif:add')")
    @Log(title = "题目主题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurveysQuestionMotif surveysQuestionMotif)
    {
        surveysQuestionMotif.setCreateBy(SecurityUtils.getUsername());
        return toAjax(surveysQuestionMotifService.insertSurveysQuestionMotif(surveysQuestionMotif));
    }

    /**
     * 修改题目主题
     */
    @PreAuthorize("@ss.hasPermi('surveys:motif:edit')")
    @Log(title = "题目主题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurveysQuestionMotif surveysQuestionMotif)
    {
        surveysQuestionMotif.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(surveysQuestionMotifService.updateSurveysQuestionMotif(surveysQuestionMotif));
    }

    /**
     * 删除题目主题
     */
    @PreAuthorize("@ss.hasPermi('surveys:motif:remove')")
    @Log(title = "题目主题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{questionMotifIds}")
    public AjaxResult remove(@PathVariable Long[] questionMotifIds)
    {
        return toAjax(surveysQuestionMotifService.deleteSurveysQuestionMotifByIds(questionMotifIds));
    }
}
